app.register.controller("UserLoginCtrl", ["$rootScope", "$scope", "$location", "$timeout", "$window", "ToastMessage", "SecurityService", "UserService", function($rootScope, $scope, $location, $timeout, $window, ToastMessage, SecurityService, UserService) {
    app.register.controller("LoginCtrl", ["$rootScope", "$scope", "$location", "$timeout", "$window", "ToastMessage", "SecurityService", "UserService", function($rootScope, $scope, $location, $timeout, $window, ToastMessage, SecurityService, UserService) {
        var cert = app.credential.get()
          , isBackIndex = !0;
        if (null  != cert)
            return void $location.path("/index").replace();
        var cert = app.credential.get();
        $scope.credential = cert,
        $scope.cert = {
            username: "",
            password: ""
        },
        $scope.login = function(event) {
            return $scope.cert.username && $scope.cert.password ? (app.util.setDisabled(event.target),
            app.util.loading(event.target, !0),
            $timeout(function() {
                $(".psw").blur()
            }, 10),
            $timeout(function() {
                SecurityService.login($scope.cert).success(function(data) {
                    app.util.setEnabled(event.target),
                    data && data.message && ToastMessage.show(data.message, data.success),
                    data && data.success && (isBackIndex = !1,
                    app.credential.set(data.result),
                    app.credential.refresh(function() {
                        var ForwardAction = UserService.cache("ForwardAction");
                        "OpenAccount" == ForwardAction ? funs.isOpenAccount(function(status) {
                            status && "FAILED" != status && "CANCEL" != status ? $location.url("/openaccount/state") : $location.url("/openaccount/flow/cert")
                        }) : $location.path("/index").replace()
                    })),
                    app.util.loading(event.target, !1)
                }).error(function() {
                    app.util.setEnabled(event.target),
                    app.util.loading(event.target, !1)
                })
            }, 1),
            !1) : void 0
        }
        ,
        $scope.topage = function(url) {
            isBackIndex = !1,
            $location.url(url)
        }
        ,
        $scope.$on("$destroy", function() {
            app.util.pageBlur(),
            isBackIndex && $location.url("/index")
        });
        var funs = {
            loadWexin: function() {
                SecurityService.wexinInfo().success(function(data) {
                    data && data.success && ($scope.wexin = data.result)
                })
            },
            isOpenAccount: function(callback) {
                UserService.isOpenAccount().success(function(data) {
                    if (data && data.success) {
                        var status = data.result;
                        callback(status)
                    } else
                        ToastMessage.show(data.message, !1)
                })
            }
        };
        $scope.isapp || funs.loadWexin()
    }
    ]),
    $scope.isapp ? $scope.loginUrl = "template/user/app/login.html" : $scope.loginUrl = "template/user/wx/login.html"
}
]);
